package bairui.international.weixin.portal.miniapp.controller.request.agent;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.lianjing.sh.validate.spring.exception.ValidateObjectException;

import bairui.international.model.status.State_UserAgentRequestOrder;
import bairui.international.service.Service_UserAgentRequestOrder;
import lombok.Getter;
import lombok.Setter;

/**
 *
 * 申请
 *
 * @generated
 * 
 * @see STest_C_Request_Agent_Submit_Post 测试
 *
 */
@Controller
public class C_Request_Agent_Submit_Post
 extends SC_Request_Agent_Submit_Post 
{
	
	@Autowired private Service_UserAgentRequestOrder service_UserAgentRequestOrder;
	
	/**
	 * Post请求
	 */
	@Action(Post.class)
	@PostMapping(Post.RequestMappingValue)
	public @FomatOutput @ResponseBody Object post(
		ModelMap map, HttpServletRequest request,
		@RequestParam String skey, 
		@RequestBody Input input
	) throws Exception {
		// 验证
		if(service_UserAgentRequestOrder.exists(it->it.user.skey.eq(skey).and(it.state.ne(State_UserAgentRequestOrder.NoPassed)))){
			throw new ValidateObjectException("object", "", "已经申请，审核中请耐心等待");
		}
		//
		service_UserAgentRequestOrder.create(
				skey, 
				input.getName(), 
				input.getPhone(), 
				input.getCompany(), 
				input.getAddress()
			);
		//
		return null;
	}
	
	public static class Input {
		private @Getter @Setter String name;
		private @Getter @Setter String phone;
		private @Getter @Setter String company;
		private @Getter @Setter String address;
	}
	
}
